<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
  <style type="text/css">

/* tooltip */
#tooltip{
  position:absolute;
  border:1px solid #ccc;
  background:#333;
  padding:2px;
  display:none;
  color:#fff;
}
</style>
</head>
<body>
<fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
  <form class="layui-form serch" action="{:url('admin/news/index')}" method="post">
    <div class="layui-form-item" style="float: left;">
      <div class="layui-input-inline">
        <input type="text" name="keywords" lay-verify="title" value="{$Request.param.keywords}" autocomplete="off" placeholder="请输入关键词" class="layui-input layui-btn-sm">
      </div>
      <div class="layui-input-inline">
        <div class="layui-inline">
            <select name="news_cate_id" lay-search="">
              <option value="">分类</option>
              {volist name="$info.cate" id="vo"}
                {eq name="$vo.id" value="$Request.param.news_cate_id"}
                  <option value="{$vo.id}" selected>{$vo.name}</option>
                {else/}
                  <option value="{$vo.id}">{$vo.name}</option>
                {/eq}
              {/volist}
            </select>
        </div>
      </div>
      <div class="layui-input-inline">
        <div class="layui-inline">
            <select name="status" lay-search="">
              <option value="">状态</option>
              <option value="0" {eq name="$Request.param.status" value="0"}selected{/eq}>待审核</option>
              <option value="1" {eq name="$Request.param.status" value="1"}selected{/eq}>已审核</option>
            </select>
        </div>
      </div>
      <div class="layui-input-inline">
        <div class="layui-inline">
            <select name="is_top" lay-search="">
              <option value="">置顶</option>
              <option value="0" {eq name="$Request.param.is_top" value="0"}selected{/eq}>未置顶</option>
              <option value="1" {eq name="$Request.param.is_top" value="1"}selected{/eq}>已置顶</option>
            </select>
        </div>
      </div>
      <div class="layui-input-inline">
        <div class="layui-inline">
          <div class="layui-input-inline">
            <input type="text" class="layui-input" id="create_time" value="{$Request.param.create_time}" placeholder="创建时间" name="create_time">
          </div>
        </div>
      </div>
      <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
      <a class="layui-btn layui-btn-primary" href="{:url('admin/news/index')}" class="a_menu">
        重置
      </a>
      <a href="{:url('admin/news/publish')}" class="layui-btn layui-btn-sm a_menu">
        添加新闻
      </a>
    </div>
  </form> 
  
</fieldset>
<table class="layui-table" lay-even="" lay-skin="row" lay-size="sm">
  <colgroup>
    <col width="50">
    <col width="300">
    <col width="50">
    <col width="100">
    <col width="100">
    <col width="150">
    <col width="100">
    <col width="150">
    <col width="50">
    <col width="50">
    <col width="100">
  </colgroup>
  <thead>
    <tr>
      <th>ID</th>
      <th>新闻标题</th>
      <th>缩略图</th>
      <th>简介</th>
      <th>分类</th>
      <th>内容</th>
      <th>创建时间</th>
      <th>最后修改时间</th>
      <th>置顶</th>
      <th>审核状态</th>
      <th>操作</th>
    </tr> 
  </thead>
  <tbody>
    {volist name="news" id="vo"}
    <tr>
      <td>{$vo.id}</td>
      <td>{$vo.title}</td>
      <td><a href="{$vo.thumb|geturl}" class="tooltip"><img src="{$vo.thumb|geturl}" width="20" height="20"></a></td>
      <td>{$vo.description}</td>
      <td>{$vo.news.name}</td>
      <td>{$vo.content|mb_substr=0,3,'utf-8'}......<a style="color: blue" onclick="read('{$vo.id}')">查看全文</a></td>
      <td>{$vo.create_time|date='Y/m/d H:i:s',###}</td>
      <td>{$vo.update_time|date='Y/m/d H:i:s',###}</td>
      <td><a href="javascript:;" style="font-size:18px;" class="is_top" data-id="{$vo.id}" value="{$vo.is_top}" data-val="{$vo.is_top}">{eq name="vo.is_top" value="1"}<i class="fa fa-toggle-on"></i>{else /}<i class="fa fa-toggle-off"></i>{/eq}</a></td>
      <td><a href="javascript:;" style="font-size:18px;" class="status" data-id="{$vo.id}" value="{$vo.is_top}" data-val="{$vo.status}">{eq name="vo.status" value="1"}<i class="fa fa-toggle-on"></i>{else /}<i class="fa fa-toggle-off"></i>{/eq}</a></td>
      <td class="operation-menu">
        <a href="{:url('admin/news/publish',['id'=>$vo.id])}" class="layui-btn layui-btn-xs a_menu" style="margin-right: 0;font-size:12px;">修改</a>
        <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger delete" id="{$vo.id}" style="margin-right: 0;font-size:12px;">删除</a>
      </td>
    </tr>
    {/volist}
  </tbody>
</table>
        
<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
        var message;
        layui.config({
            base: '__JS__/',
            version: '1.0.1'
        }).use(['app', 'message'], function() {
            var app = layui.app,
                $ = layui.jquery,
                layer = layui.layer;
            //将message设置为全局以便子页面调用
            message = layui.message;
            //主入口
            app.set({
                type: 'iframe'
            }).init();
        });
    </script> 
<script type="text/javascript">
$(function(){
  var x = 10;
  var y = 20;
  $(".tooltip").mouseover(function(e){ 
    var tooltip = "<div id='tooltip'><img src='"+ this.href +"' alt='产品预览图' height='200'/>"+"<\/div>"; //创建 div 元素
    $("body").append(tooltip);  //把它追加到文档中             
    $("#tooltip")
      .css({
        "top": (e.pageY+y) + "px",
        "left":  (e.pageX+x)  + "px"
      }).show("fast");    //设置x坐标和y坐标，并且显示
    }).mouseout(function(){  
    $("#tooltip").remove();  //移除 
    }).mousemove(function(e){
    $("#tooltip")
      .css({
        "top": (e.pageY+y) + "px",
        "left":  (e.pageX+x)  + "px"
      });
  });
})

$('.delete').click(function(){
  var id = $(this).attr('id');
  layer.confirm('确定要删除?', function(index) {
    $.ajax({
      url:"{:url('admin/news/delete')}",
      data:{id:id},
      success:function(res) {
        layer.msg(res.msg);
        if(res.code == 1) {
          setTimeout(function(){
            location.href = res.url;
          },1500)
        }
      }
    })
  })
})

function read(content_id) {
  //alert(content_id);
  $.post('read',{id:content_id},function (r) {

    r=JSON.parse(r);
    layer.confirm(r);
    //alert(JSON.parse(r));
  })
}
</script>
<script type="text/javascript">
$('.a_menu').click(function(){
  var url = $(this).attr('href');
  var id = $(this).attr('id');
  var a = true;
  if(id) {
    $.ajax({
      url:url
      ,async:false
      ,data:{id:id}
      ,success:function(res){
        if(res.code == 0) {
          layer.msg(res.msg);
          a = false;
        }
      }
    })
  } else {
    $.ajax({
      url:url
      ,async:false
      ,success:function(res){
        if(res.code == 0) {
          layer.msg(res.msg);
          a = false;
        }
      }
    })
  }
  return a;
})

$('.is_top').click(function(){
  var val = $(this).attr('data-val');
  var id = $(this).attr('data-id');
  var i = $(this).find('i');
  var value= $(this).attr('value');
  var the = $(this);
  if(value == 1){
    var is_top = 0;
  } else {
    var is_top = 1;
  }
  $.ajax({
    type:"post",
    url:"{:url('admin/news/is_top')}",
    data:{is_top:is_top,id:id},
    success:function(res){
      
      if(res.code == 1) {
        top();
        layer.msg(res.msg);
      } else {
        layer.msg(res.msg);
      }
    }
  })

  function top(){
    if(value == 1){
      i.attr("class","fa fa-toggle-off");
      the.attr('data-val',0);
      the.attr('value',0);
    } else {
      i.attr("class","fa fa-toggle-on");
      the.attr('data-val',1);
      the.attr('value',1);
    }
  }
})


$('.status').click(function(){
  var val = $(this).attr('data-val');
  var id = $(this).attr('data-id');
  var i = $(this).find('i');
  var value= $(this).attr('value');
  var the = $(this);
  if(value == 1){
    var status = 0;
  } else {
    var status = 1;
  }
  $.ajax({
    type:"post",
    url:"{:url('admin/news/status')}",
    data:{status:status,id:id},
    success:function(res){
      
      if(res.code == 1) {
        tostatus();
        layer.msg(res.msg);
      } else {
        layer.msg(res.msg);
      }
    }
  })

  function tostatus(){
    if(value == 1){
      i.attr("class","fa fa-toggle-off");
      the.attr('data-val',0);
      the.attr('value',0);
    } else {
      i.attr("class","fa fa-toggle-on");
      the.attr('data-val',1);
      the.attr('value',1);
    }
  }
})
</script>
<script>
layui.use('laydate', function(){
  var laydate = layui.laydate;
  
  //常规用法
  laydate.render({
    elem: '#create_time'
  });
});
</script>
</body>
</html>
